package com.example.sams.controller;

import com.example.sams.service.ICoursesService;
import com.example.sams.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 课程表 前端控制器
 * </p>
 *
 * @author jinghong
 * @since 2025-11-04
 */
@RestController
@RequestMapping("/courses")
public class CoursesController {

    @Autowired
    private ICoursesService coursesService;

    /**
     * 获取课程列表（已审核通过的）
     * GET /courses?approved=true
     */
    @GetMapping
    public ResultUtil getCourses(@RequestParam(required = false, defaultValue = "true") Boolean approved) {
        if (approved != null && approved) {
            // 只返回已审核通过的课程
            return coursesService.getApprovedCourses();
        } else {
            // 如果不需要过滤，也可以返回所有课程（这里暂时只返回已审核通过的）
            return coursesService.getApprovedCourses();
        }
    }
}
